package com.domain.service.impl;

import com.domain.common.Result;
import com.domain.dao.CommentMapper;
import com.domain.dao.PublishAcceptanceMapper;
import com.domain.pojo.Comment;
import com.domain.pojo.Publish;
import com.domain.pojo.PublishAcceptance;
import com.domain.service.PublishAcceptanceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class PublishAcceptanceServiceImpl implements PublishAcceptanceService {

    @Autowired
    private PublishAcceptanceMapper publishAcceptanceMapper;
    @Autowired
    private CommentMapper commentMapper;

    /**
     * 获取我的帮忙列表
     *
     * @param userId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Result getUsersPublishAcceptanceList(String userId, String pageNum, String pageSize) {
        PageHelper.startPage(new Integer(pageNum), new Integer(20));
        List<Map<String, Object>> lists = publishAcceptanceMapper.selectByUserId(userId);
        if (lists.size() == 0) {
           /* paTime userId uname uNickName uHeadImage pId title ptype pItIsPaid itisRedPackge */
            Map<String, Object> maps = new HashMap<>();
            maps.put("paTime", "");
            maps.put("userId", "");
            maps.put("uname", "");
            maps.put("uNickName", "");
            maps.put("uHeadImage", "");
            maps.put("pId", "");
            maps.put("title", "");
            maps.put("ptype", "");
            maps.put("pItIsPaid", "");
            maps.put("itisRedPackge", "");
            lists.add(maps);
        }
        //评论列表
        List<Comment> size = new ArrayList<>();
        PageInfo pageResult = new PageInfo(lists);
        for (Map<String, Object> p : lists
                ) {
            size = commentMapper.selectBypublishId(p.get("pId").toString());

        }
        Map<String, Object> maps = new HashMap<>();
        maps.put("publishList", pageResult.getList());
        maps.put("commentsSize", size.size());
        return Result.success("操作成功", maps);
    }
}
